# -*- coding=UTF-8 -*-
# @Project          WeChatPublicNumberPushInformation
# @fileName         time_calculation.py
# @author           Echo
# @EditTime         2024/9/10
from time import strptime
from typing import *


def time_diff(time1: Text, time2: Text, format) -> int:
    """
    计算两个时间差
    :param time1: 时间1
    :param time2: 时间2
    :param format: 时间格式
    :return: 时间差
    """
    import datetime
    time1 = datetime.datetime.strptime(time1, format)
    time2 = datetime.datetime.strptime(time2, format)
    if time2 > time1:
        return (time2 - time1).days
    else:
        print("时间1大于时间2, 请检查")


def calculate_birthday(birthday: Text) -> int:
    """
    计算生日
    :param birthday: 出生日期
    :param format: 时间格式
    :return: 生日
    """
    from datetime import date, datetime
    today = date.today()

    # 解析生日字符串
    birthday_month, birthday_day = map(int, birthday.split('-'))

    # 计算今年的生日日期
    this_year_birthday = date(today.year, birthday_month, birthday_day)

    # 如果今年的生日已经过了，就计算明年的生日
    if this_year_birthday < today:
        next_birthday = date(today.year + 1, birthday_month, birthday_day)
    else:
        next_birthday = this_year_birthday

    # 计算天数差
    days_left = (next_birthday - today).days
    return days_left


def claculate_love_date(love_date: Text) -> int:
    """
    计算恋爱日
    :param love_date: 
    :return: 
    """
    from datetime import date, datetime

    anniversary_date = datetime.strptime(love_date, "%Y-%m-%d").date()
    today = date.today()
    days_passed = (today - anniversary_date).days
    return days_passed


def claculate_exam_countdown(exam_date: Text) -> int:
    """
    计算考试倒计时
    :param exam_date: 考试时间
    :return: 
    """
    from datetime import date, datetime
    today = date.today()
    exam_date = datetime.strptime(exam_date, "%m-%d").date()
    exam_date = exam_date.replace(year=today.year)
    # if exam_date < today:
    #     exam_date = exam_date.replace(year=today.year + 1)
    days_left = (exam_date - today).days
    return days_left


